package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.model.vo.UserInfoVoAge;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 通知设置控制层
 */
@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     * 用户通用设置 - 读取
     */
    @RequestMapping(value = "/settings",method = RequestMethod.GET)
    public ResponseEntity findSettings(){
        SettingsVo settingsVo = settingsService.findSettings();
        return ResponseEntity.ok(settingsVo);
    }


    /**
     * 设置陌生人问题 - 保存
     */
    @RequestMapping(value = "/questions",method = RequestMethod.POST)
    public ResponseEntity addOrUpdateQuestions(@RequestBody Map<String,String> params){
        String content = params.get("content");
        settingsService.addOrUpdateQuestions(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 通知设置 - 保存
     */
    @RequestMapping(value = "/notifications/setting",method = RequestMethod.POST)
    public ResponseEntity addOrUpdateSettings(@RequestBody SettingsVo settingsVo){
         //推送喜欢通知 //推送评论通知 //推送公告通知
        settingsService.addOrUpdateSettings(settingsVo);
        return ResponseEntity.ok(null);
    }

    /**
     * 黑名单 - 分页列表
     */
    @RequestMapping(value = "/blacklist",method = RequestMethod.GET)
    public ResponseEntity findPageBlacklist(@RequestParam(value = "page",defaultValue = "1") Long page, @RequestParam(value = "pagesize",defaultValue = "10")Long pageSize){
        PageResult<UserInfoVoAge> pageResult = settingsService.findPageBlacklist(page,pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 黑名单 - 移除
     * uid:黑名单用户id
     */
    @RequestMapping(value = "/blacklist/{uid}",method = RequestMethod.DELETE)
    public ResponseEntity deleteBlacklistById(@PathVariable("uid") Long blackUserId){
        settingsService.deleteBlacklistById(blackUserId);
        return ResponseEntity.ok(null);
    }
}
